#include "pch.hpp"

#include "item.h"

void item::load(BallType::Type blType,sf::Vector2f pos,sf::Vector2f dir,float vel)
{
	curr_angle = 0;
	bType = blType;
	position = pos;
	direction = dir;
	velocity = vel;
	sfm::Normalize(direction);
	dead = false;
	animate = true;
}

bool item::step()
{
	if(!animate) return false;

	position.x += (direction.x * velocity) * 1.0f/60.0f;
	position.y += (direction.y * velocity) * 1.0f/60.0f;

	float leng = sfm::Length(sf::Vector2f(position.x, position.y-768/2.0f));
	if(leng<5)
	{
		playSound("hamsterHit");
		dead = true;
	}
	return dead;
}

void item::draw()
{
	sf::Image& img = GetBallImage(bType);
	sf::Sprite spr(img);
	spr.SetCenter(img.GetWidth()/2.0f, img.GetHeight()/2.0f);
	spr.SetPosition(position);
	app.Draw(spr);
}

sf::Vector2f item::getPosition()
{
	return position;
}

BallType::Type item::getBallType()
{
	return bType;
}
